<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\model\SysmsgAbout as SysmsgAboutModel;
use app\api\validate\ParameterMustBePositiveInteger;
use think\Request;

/**
 * 系统消息和关于我们
 * Class SysmsgAbout
 * @package app\api\controller\v1
 */
class SysmsgAbout extends BaseController
{
    /**
     * @desc 检查用户权限
     */
    protected $beforeActionList = [
        'checkUserScope' => ['only' => 'getsysmsglist'], // 方法名必须全部小写，逗号中间不能有空格！！！
    ];

    /**
     * @Desc 获取系统消息和关于我们
     * @return array
     */
    public function getSysmsgList()
    {
        (new ParameterMustBePositiveInteger())->scene('sysmsg')->goCheck();
        $param = Request::instance()->param();
        return SysmsgAboutModel::getSysmsgList($param['type'], $param['page']);
    }

    /**
     * @Desc 获取系统消息详情
     * @return array
     */
    public function getSysmsgDetail($id)
    {
        (new ParameterMustBePositiveInteger())->scene('id')->goCheck();
        return SysmsgAboutModel::getSysmsgDetail($id);
    }

    /**
     * @Desc 获取更新信息
     * @return array
     */
    public function getUpdate()
    {
        $update = SysmsgAboutModel::getUpdate();
        $update['now_time'] = time();
        $code = $update['now_time'] < $update['start_time'] ? 1 : 0;
        return [
            'code' => $code,
            'list' => $update,
        ];
    }
}